package com.zxkj.commonpatrol.repoisity;

import com.allen.library.base.BaseHttpUtil;
import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.constant.ItrackConstant;
import com.czy.basecommon.utils.tools.GsonUtil;
import com.czy.basecommon.utils.tools.SPUtils;
import com.zxkj.commonpatrol.model.post.PostPointInfo;
import com.zxkj.commonpatrol.model.post.PostSearchProject;
import com.zxkj.commonpatrol.model.response.InspectionDetailResponse;
import com.zxkj.commonpatrol.model.response.PointCategoryResponse;
import com.zxkj.commonpatrol.model.response.PointInfoResponse;
import com.zxkj.commonpatrol.net.ETFApiHelper;

import java.util.HashMap;
import java.util.List;

import okhttp3.ResponseBody;

public class AddCheckPointRepoisity extends BaseRepository {
    public AddCheckPointRepoisity() {

    }


    //获取种类

    public  void  getTypeList(String Code,MyBaseDataCallBack mDataCallBack){
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID,""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN,""));
        map.put("Lang", 1);
        ETFApiHelper.geRadomApi().getPointCategorys(map,Code)
                .compose(Transformer.<List<PointCategoryResponse>>switchSchedulers())
                .subscribe(new CommonObserver<List<PointCategoryResponse>>() {
                    @Override
                    protected String setTag() {
                        return "RouteSystems";
                    }

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(List<PointCategoryResponse> s) {

                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });

    }






    //获取 详情
    public  void getTypeDetail(String COde,MyBaseDataCallBack mDataCallBack){
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID,""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN,""));
        map.put("Lang", 1);
        ETFApiHelper.geRadomApi().getBookCheckPoints(map,COde)
                .compose(Transformer.<PointInfoResponse>switchSchedulers())
                .subscribe(new CommonObserver<PointInfoResponse>() {

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(PointInfoResponse s) {

                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });
    }

    public  void  Save(PointInfoResponse pointInfoResponses,MyBaseDataCallBack  mDataCallBack){
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID,""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN,""));
        map.put("Lang", 1);

        ETFApiHelper.geRadomApi().SaveCheckPoint(map,new BaseHttpUtil().toJson(GsonUtil.getGson().toJson(pointInfoResponses)))
                .compose(Transformer.<ResponseBody>switchSchedulers())
                .subscribe(new CommonObserver<ResponseBody>() {

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(ResponseBody s) {

                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });
    }


}
